package poketrade;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import poketrade.entities.User;
import poketrade.managers.UserManager;

/**
 * Servlet implementation class ModifyUserServlet
 */
@WebServlet("/ModifyUserServlet")
public class ModifyUserServlet extends BaseHttpServlet {
	private static final long serialVersionUID = 1L;
    
	@EJB
	private UserManager mgr;
	
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession s = request.getSession();
		User u = (User) s.getAttribute("user");
		
		u = mgr.updateUser(u.getId(),
				request.getParameter("email"),
				request.getParameter("adresse"),
				request.getParameter("ville"),
				request.getParameter("dep"));
		s.setAttribute("user", u);
		
		showMessage(request, response, "Modifications appliquées avec succès");
	}

}
